/*
 * This file is generated and updated by Sencha Cmd. You can edit this file as needed for your application, but these
 * edits will have to be merged by Sencha Cmd when upgrading.
 */
function debug(){ }

Ext.application({

	name : 'byb',
	requires : [ "Ext.util.Cookies", "byb.workspace",
			"byb.view.window.UserLoginWindow", "byb.Constant", "byb.AdmCode",
			"Ext.data.*", "Ext.ux.grid.Printer"],
	controllers : [ "BaseController", "MenuController", "SystemController"
	],
	stores : [ "DictStore"],
	launch : function() {
		var workspace = Ext.create("byb.workspace");
		workspace.init();
	}
});


Ext.onReady(function() {

    /**
     * 用来监听消息
     */
    Ext.Ajax.on("requestcomplete",function(conn,response,options,eOpts ){
    	
        if(!response.getResponseHeader("content-type")||response.getResponseHeader("content-type").indexOf("json")===-1){
            return;
        }
        
        if(response.status===200&&response.responseText.length>0){
            var result=Ext.decode(response.responseText);
            if(result.success===false&&result.message){
                Ext.MessageBox.show({
                    title:byb.Constant.ExceptionServerOperation,
                    msg:result.message,
                    buttons:Ext.Msg.OK
                });
            }
        }
    });

    Ext.Ajax.on("requestexception",function(conn,response,options,eOpts ){
        if(response.status===500){
            Ext.MessageBox.show({
                title:byb.Constant.ExceptionServerOperation,
                msg:response.responseText,
                buttons:Ext.Msg.OK
            });
        }else if(response.status===400){
            Ext.MessageBox.show({
                title:byb.Constant.ExceptionServerOperation,
                msg:"刷新后请求!",
                buttons:Ext.Msg.OK
            });
        }else if(response.status===901){
	        if("rest/user/getLoginInfo" != options.url){
	        	Ext.Msg.alert('提示', '会话超时，请重新登录!', function(){
		            window.location = "index.html"; 
		        });
	        }
	    }else if(response.status===403){
	        Ext.Msg.alert('提示', '该资源禁止访问!');
	    }
    });


    Ext.apply(Ext.data.validations,{
        "sheetValidateMessage":"工单填写错误",
        "sheetValidate":function(config,value){
            if(value){
                for(var i=0;i<value.length;i++){
                    var row=value[i];
                    if(row.quantity<0){
                        var operation="入库";
                        if(config.sheetType().indexOf("SOT_OW")!=-1){
                            operation="出库";
                        }
                        this.sheetValidateMessage="第【"+(i+1)+"】行【"+operation+"数量】不能为负数";
                        return false;
                    }
                }
            }
            return true;
        }
    });

	//非特殊字符字符串验证,可以有中文
	var normalWithChinese= /^([\u4e00-\u9fa5|a-zA-Z0-9]+)$/;	
	//非特殊字符字符串验证,不可以包含中文
	var normal= /^([a-zA-Z0-9]+)$/;

    //var mobile=/^(?:13\d|15[89])-?\d{5}(\d{3}|\*{3})$/;
	var mobile=/^1[34578][0-9]-?\d{8}$/;
	
    //var phone=/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;
	var phone=/^(([0\+]\d{2,3}-)?0\d{2,3}-)?\d{7,8}(-\d{1,4})?$/;
	
	// 定义密码验证
	Ext.apply(Ext.form.field.VTypes, {
		normal: function(val){
			return normal.test(val);
		}
		,normalWithChinese: function(val){
			return normalWithChinese.test(val);
		}
        ,normalWithChineseText:"只能输入中文,英文和数字!"
        ,normalText:"只能输入英文和数字!"
        	
		// 密码确认验证
		,password : function(val, field) {
			if (field.initialPassField) {
				var pwd = field.up('form').down('#' + field.initialPassField);
				return (val == pwd.getValue());
			}
			return true;
		},
        telOrMobilePhone:function(val,field){
            if(mobile.test(val)||phone.test(val)){
                return true;
            }else{
                return false;
            }
        },
        telOrMobilePhoneText:"手机号/电话号不合法(区号-号码)"
        ,tel:function(val,field){
            return phone.test(val);
        }
		,telText:"电话号不合法(区号-号码)"
	});
});
